//
// Created by tang on 2022/3/30.
//

#include "input.hpp"
#include "log.hpp"
#include "ioc.hpp"
#include "app.hpp"
#include "gpio.hpp"

static double total_time = 0.0;

Pulse *p = nullptr;
static int freq = 40;

Input::Input() {
    LOG_D("Input Sub System Create.");

    Initialize();
}

Input::~Input() {
    LOG_D("Input Sub System Destroy.");
}

void Input::OnUpdate(double delta_time) {
//    LOG_D("Input Sub System Update: delta time is %lf", delta_time);

    p->SetFrequency(freq += 20);
    LOG_I("current frequency is : %d", p->Frequency());
    total_time += delta_time;
    if (total_time >= 30.0)
        IoC::Container::Current()->Resolve<App>()->Quit();
}

void Input::Initialize() {
    LOG_D("Input Sub System Initializing ...");

    p = new Pulse(4, freq, 0.2);
}
